package org.iba.coobob;

import java.util.ArrayList;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.oned.Code128Writer;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Color;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;

public class Payment extends Activity  {

	private ImageView imageView_Barcode;
	private Bitmap mBitmap ;
	private int barcodeHeight;
	private int barcodeWidth;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_payment);





		imageView_Barcode = (ImageView)findViewById(R.id.imageView_Barcode);
		imageView_Barcode.setDrawingCacheEnabled(true);
		mBitmap = imageView_Barcode.getDrawingCache();
		generateBarCode("12345678");
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.payment, menu);
		return true;
	}
	public void generateBarCode(String data){
		com.google.zxing.Writer c9 = new Code128Writer();
		barcodeHeight = (int)getResources().getDimension(R.dimen.barcode_height);
		barcodeWidth = (int) getResources().getDimension(R.dimen.barcode_width);

		try {
			BitMatrix bm = c9.encode(data,BarcodeFormat.CODE_128,barcodeWidth, barcodeHeight);
			mBitmap = Bitmap.createBitmap(barcodeWidth, barcodeHeight, Config.ARGB_8888);

			for (int i = 0; i < barcodeWidth; i++) {
				for (int j = 0; j <barcodeHeight; j++) {

					mBitmap.setPixel(i, j, bm.get(i, j)? Color.BLACK : Color.WHITE);

				}
			}
		} catch (WriterException e) {
			e.printStackTrace();
		}
		if (mBitmap != null) {
			//WimageView_Barcode.setScaleType(ScaleType.FIT_XY);
			imageView_Barcode.setImageBitmap(mBitmap);
		}
	}

	

}
